package com.jiuwu.bluetoothlegatt;

/**
 * Created by zhangjun on 15/10/25.
 */
public class BpData {

    public static final int IDEA =  0;
    public static final int STARTING = 1;
    public static final int WORKING = 2;
    public static final int FINISH = 3;
    public static final int CLOSED = 4;


    public byte[] data;

    public int  state;

    /** 压力值*/
    public int pressure;

    public BpResult bpResult;

    public BpData(byte[] data){
        this.data = data;
        if(data.length == 1 && data[0] == (byte)0xA5){
            state = IDEA;
        }else if(data.length > 3){
            switch (data[2]){
                case 0x06:
                    state = STARTING;
                    break;
                case 0x07:
                    state = CLOSED;
                    break;
                case (byte)0xFB:
                    state = WORKING;
                    pressure = data[3] * 256 + data[4]&0xFF;
                    break;
                case (byte)0xFC:
                    state = FINISH;
                    bpResult = new BpResult(data[3]&0xFF,data[4]&0xFF,data[5]&0xFF);
                    break;
                case (byte)0xFD:
                    state = FINISH;
                    bpResult = new BpResult(data[3]);
                    break;


            }

        }


    }




    public static boolean isBpData(byte[] data){
        if(null == data) return false;
        if(data.length == 1 && data[0] == (byte)0xA5){
            return true;
        }else if(data[0] == (byte)0xFD && data[1]== (byte)0xFD && data[data.length-2] ==  0x0D && data[data.length-1]== 0x0A){
            return true;
        }else{
            return false;
        }
    }


}
